package main

import (
	"container/list"
	"fmt"
)

//用两个栈实现一个队列。队列的声明如下，请实现它的两个函数 appendTail 和 deleteHead ，分别完成在队列尾部插入整数和在队列头部删除整数的功能。
//(若队列中没有元素，deleteHead操作返回 -1 )

//示例 1：
//输入：
//["CQueue","appendTail","deleteHead","deleteHead"]
//[[],[3],[],[]]
//输出：[null,null,3,-1]
//示例 2：
//输入：
//["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]
//[[],[],[5],[2],[],[]]
//输出：[null,-1,null,null,5,2]

type CQueue struct {
	stkOne, stkTwo *list.List
}

func Constructor() CQueue {
	return CQueue{ // 构造的结构体变量直接返回
		list.New(),
		list.New(),
	}
}

// 使用字面量的初始化值
//type Person struct {
//    name string
//    age int
//    address string
//}
//
//func main() {
//    var p1 Person
//    p1 = Person{"lisi", 30, "shanghai"}   //方式A
//    p2 := Person{address:"beijing", age:25, name:"wangwu"} //方式B
//    p3 := Person{address:"NewYork"} //方式C
//}

func (this *CQueue) AppendTail(value int) {
	this.stkOne.PushBack(value)
}

func (this *CQueue) DeleteHead() int {
	if this.stkTwo.Len() == 0 {
		for ; this.stkOne.Len() != 0; this.stkOne.Remove(this.stkOne.Back()) {
			this.stkTwo.PushBack(this.stkOne.Back().Value)
		}
	}

	if this.stkTwo.Len() != 0 {
		e := this.stkTwo.Back()
		this.stkTwo.Remove(e)
		fmt.Println(e.Value)
		v, _ := e.Value.(int)
		return v
	}
	fmt.Println(-1)
	return -1
}

/**
 * Your CQueue object will be instantiated and called as such:
 * obj := Constructor();
 * obj.AppendTail(value);
 * param_2 := obj.DeleteHead();
 */

func main(){
	queue := Constructor()
	queue.AppendTail(3)
	queue.DeleteHead()
	queue.DeleteHead()
}
